package com.jtlrm.ckd.mvp.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.base.sdk.base.net.CommonObserver;
import com.base.sdk.util.ValidateUtils;
import com.jtlrm.ckd.R;
import com.jtlrm.ckd.base.acitvity.TitleBarActivity;
import com.jtlrm.ckd.entity.ByPhoneHuanZheInfo;
import com.jtlrm.ckd.mvp.model.HuanZheGuanLiModel;

import butterknife.BindView;

public class NewHuanZheJianDangActivity extends TitleBarActivity {

    @BindView(R.id.phone)
    EditText phoneE;
    HuanZheGuanLiModel huanZheGuanLiModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected String getTitleText() {
        return "新患者建档";
    }

    @Override
    protected void setContentLayout() {
        setContentView(R.layout.activity_new_huan_zhe_jian_dang);
    }

    @Override
    protected void initView() {
        huanZheGuanLiModel = new HuanZheGuanLiModel();
    }

    @Override
    protected void obtainData() {

    }

    @Override
    protected void initEvent() {

    }

    public void submit(View view) {
        String phone = getTextStr(phoneE);
        if (ValidateUtils.Mobile(phone)) {
            queryInfo(phone);
        } else {
            showToast("请输入正确的手机号");
        }
    }

    private void queryInfo(final String phone) {
        showLoadingDialog("查询中");
        huanZheGuanLiModel.queryHuanZheByPhone(phone, new CommonObserver<ByPhoneHuanZheInfo>() {
            @Override
            public void onError(int errType, String errMessage) {
                dismissLoadingDialog();
                NewHuanZheJianDangActivity2.goActivity(context, phone, null);
                finish();
            }

            @Override
            public void onResult(ByPhoneHuanZheInfo data) {
                dismissLoadingDialog();
                NewHuanZheJianDangActivity2.goActivity(context, phone, data);
                finish();
            }
        }, lifecycleSubject);
    }
}
